package cn.chenfeifx.core.common;

import javafx.scene.Node;
import javafx.scene.SnapshotParameters;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.paint.Color;

/**
 * 剪贴板工具
 */
public class ClipboardUtils {

    private static final Clipboard SYSTEM_CLIPBOARD = Clipboard.getSystemClipboard();
    private static final ClipboardContent CLIPBOARD_CONTENT = new ClipboardContent();

    public static void setString(String val) {
        CLIPBOARD_CONTENT.clear();
        CLIPBOARD_CONTENT.putString(val);
        SYSTEM_CLIPBOARD.setContent(CLIPBOARD_CONTENT);
    }

    public static String getString() {
        return SYSTEM_CLIPBOARD.getString();
    }

    public static void setSnapshotImage(Node node) {
        SnapshotParameters snapshotParameters = new SnapshotParameters();
        snapshotParameters.setFill(Color.TRANSPARENT); // 透明背景
        CLIPBOARD_CONTENT.clear();
        CLIPBOARD_CONTENT.putImage(node.snapshot(snapshotParameters, null)); // 设置剪贴板内容
        SYSTEM_CLIPBOARD.setContent(CLIPBOARD_CONTENT);
    }

}
